package com.example.outdoor;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;


	public class ListOfProduct extends Activity {
		 ListView lisView1;
			@Override
			public void onCreate(Bundle savedInstanceState) {
				super.onCreate(savedInstanceState);
				setContentView(R.layout.edit_product);
			
				final myDBForProduct myDb = new myDBForProduct(this);
				final ArrayList<HashMap<String, String>> MebmerList = myDb.SelectAllData();   
				
		        // listView1
		        lisView1 = (ListView)findViewById(R.id.listViewProduct); 
		        
		        SimpleAdapter sAdap;
		        sAdap = new SimpleAdapter(ListOfProduct.this, MebmerList, R.layout.edit_prouct_column,
		                new String[] {"ID","Brandcode","Branddescription"}, new int[] {R.id.ColListProductID,R.id.ColListBrandcode,R.id.ColListBranddescription});      
		        lisView1.setAdapter(sAdap);
		        
		        lisView1.setOnItemClickListener(new OnItemClickListener() {
				      public void onItemClick(AdapterView<?> myAdapter, View myView, int position, long mylng) {
				    	   
				    	  	// Show on new activity
			            	Intent newActivity = new Intent(ListOfProduct.this,updateProduct.class);
			            	newActivity.putExtra("ID", MebmerList.get(position).get("ID").toString());
			            	startActivity(newActivity);

				      }       
		        });
				   
				
				// btnCancel (Cancel)
		        final Button cancel = (Button) findViewById(R.id.btnListProductCancel);
		        cancel.setOnClickListener(new View.OnClickListener() {
		            public void onClick(View v) {        	
		            	// Open Form Main
		            	Intent newActivity = new Intent(ListOfProduct.this,EditTables.class);
		            	startActivity(newActivity);
		            }
		        });
		        
			}
	}


